

<template>
    <div class="storeInfo supplier">
        <div class="head">
            <el-form :model="form" class="headForm">
                <el-form-item label="" style="width:105px">
                    <el-input v-model="form.good_name" placeholder="商品名称"></el-input>
                </el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                <el-button type="danger" @click="theClick('add')">添加</el-button>


            </el-form>
            
        </div>
        <!-- <p style="line-height:30px;padding-left:20px;margin-top:8px;color:#333" v-if="form.order_id == ''">最近{{total}}笔人工退款订单记录</p> -->
        <!-- table -->
        <div class="tabContainer_SI tabContainer">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center" >
                <!-- 资产编号	名称	单位	价格(元)	创建时间	更新时间	操作				 -->
                <el-table-column prop="id" label="资产编号" fixed ></el-table-column>
                <el-table-column prop="good_name" label="名称"> </el-table-column>
                <el-table-column prop="unit" label="单位" ></el-table-column>
                <el-table-column prop="price" label="价格(元)" ></el-table-column>
                <el-table-column prop="create_time" label="创建时间" ></el-table-column>
                <el-table-column prop="update_time" label="更新时间"></el-table-column>
                <el-table-column prop="" label="操作" v-if="limitList.length != 0">
                    <template slot-scope="scope">
                        <span v-for="(item,indexLimit) in limitList" :key="indexLimit" class="lightFont" @click="theClick(item.url,scope.row)">
                            <i>{{item.name}}</i>
                            <i v-if="indexLimit != limitList.length-1">&nbsp;|&nbsp;</i>
                        </span>
                    </template>          
                </el-table-column>
                <el-table-column v-else label="操作">/</el-table-column>

            </el-table>                       
        </div>
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>
        <el-dialog :title="editTitle" :visible.sync="add_edit_show" class="business">
            <el-form ref="form" :model="editForm" label-width="80px">
                <el-form-item label="名称">
                    <el-input v-model="editForm.good_name"></el-input>
                </el-form-item>
                <el-form-item label="单位">
                    <el-input v-model="editForm.unit"></el-input>
                </el-form-item>
     
                <el-form-item label="价格">                    
                     <el-input v-model="editForm.price"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="add_edit_show = false">取 消</el-button>
                <el-button type="primary" @click="confrim">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<style lang="scss">
.supplier{
        .el-dialog{
            .el-dialog__body{
                min-height: 300px;

            }
        } 
    }
  .tabContainer_SI{
      .el-table{
          .cell{
              text-align: center;
          }
      }
  }
</style>

<script>
import Vue from 'vue';
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js'; 

export default {
    data () {
    return {
        tableData:[],
        total:50,
        size:20,
        form:{size:20,
            page:1
        },
        pageNum:1,
        limitList:[
            {name:"编辑",url:"edit"},
            {name:"删除",url:"del"},
        ],
        editTitle:"",
        add_edit_show:false,
        editForm:{},


    }
  }, 
   mounted(){
      let that = this;
      that.getList();
      
  },
  methods:{
    search(){
        let that = this;
        //搜索有问题，搜索2019-03数据和2019-04数据是一样的；-error
        that.getList()
    },
    changePage(val){
        var that = this;
        that.pageNum = val;
        that.form.page = val;
        that.getList()
    },
    getList(){
        let that = this;
        abc.get(that,potUrl.goodsindex,that.form,(res)=>{
            that.tableData=res.data;
            that.total = res.data.length;
        })//列表
    },
    confrim(a){
        const that = this;
        let url = '';
        that.add_edit_show = false;
        if(that.editTitle == '添加'){
            url = potUrl.goodsadd
        }else{
            url = potUrl.goodsedit
        }
        abc.post(that,url,that.editForm,(res)=>{
            that.getList()
        })
    },
    theClick(a,b){
        const that = this;
        if(a == 'del'){
            abc.twoTips(that,potUrl.goodsdel,'确定删除'+b.good_name+'吗？',{id:b.id},()=>{
                that.getList()
            })
        }else{
            that.add_edit_show = true;
            if(a == 'edit'){
                that.editTitle = "编辑："+b.good_name;
                that.editTitle.id = b.id
                abc.get(that,potUrl.goodsdetail,{id:b.id},(res)=>{
                    that.editForm = res.data
                })
            }else{
                that.editTitle = '添加';
                that.editForm = {}
            }
        }
    }
  }
}
</script>
